package com.atled.data.collections;

import java.util.Collections;
import java.util.List;

import com.atled.data.UidToObjectProvider;
import com.google.common.collect.Lists;

public class CollectionByUid<T> {

	protected List<Integer> objUids;
	protected List<T> objList;
	protected UidToObjectProvider objProvider;
	
	protected boolean isObjListDirty() {
		return objList == null;
	}
	
	@SuppressWarnings("unchecked")
	public List<T> getList() {
		if (isObjListDirty()) {
			objList = Lists.newArrayList();
			for (Integer uid : objUids) {
				objList.add((T)objProvider.getObjectByUid(uid));
			}
			objList = Collections.unmodifiableList(objList);
		}
		return objList;
	}
	
}
